﻿using System.AutoUpdate.Interfaces;
using System.AutoUpdate.Library;

namespace System.AutoUpdate.Core.Operations
{
    /// <summary>
    /// Basic operation with events
    /// </summary>
    public abstract class BasicOperation : IUpdateOperation
    {
        protected UpdateInfo Info
        {
            get;
            set;
        }

        protected void OperationEvent(OperationEvent eventType, object sender, OperationEventArgs eventArgs)
        {
            switch (eventType)
            {
                case Core.OperationEvent.Started:
                    if (OperationStarted != null)
                    {
                        OperationStarted (sender, eventArgs);
                    }

                    break;
                case Core.OperationEvent.Progress:
                    if (OperationProgressChanged != null)
                    {
                        OperationProgressChanged (sender, eventArgs);
                    }

                    break;
                case Core.OperationEvent.Completed:
                    if (OperationCompleted != null)
                    {
                        OperationCompleted (sender, eventArgs);
                    }

                    break;
            }
        }

        public abstract bool StartOperation (UpdateInfo info);

        public event OperationEventHandler OperationStarted;
        public event OperationEventHandler OperationProgressChanged;
        public event OperationEventHandler OperationCompleted;
    }
}
